package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.exception.Assert;
import com.atguigu.common.result.R;
import com.atguigu.common.result.ResponseEnum;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.pojo.vo.RegisterVO;
import com.atguigu.srb.core.pojo.vo.UserInfoVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Dragon
 * @since 2021-07-29
 */

@Api(tags = "会员接口")
@Slf4j
//@CrossOrigin
@RestController
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Autowired
     private   UserInfoService userInfoService;
    @ApiOperation("查询数据然后分页")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页面",required = true)
            @PathVariable Long page,
            @ApiParam(value = "页面大小",required = true)
            @PathVariable Long limit,
            @ApiParam(value = "查询条件",required = false)
            UserInfoQuery userInfoQuery
    ){
        Page<UserInfo> pageOne = new Page<>(page, limit);
       IPage<UserInfo> pageModel = userInfoService.listpage(pageOne,userInfoQuery);
       return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation("锁定和解锁")
    @PutMapping("/lock/{id}/{status}")
    public R lock(
            @ApiParam(value = "要锁定的ID",required = true)
            @PathVariable("id") Long id,
                  @ApiParam(value = "1为解锁0为锁定",required = true)
                  @PathVariable Integer status){

        userInfoService.lock(id,status);
        return R.ok().message(status==1?"锁定失败":"解锁成功");
    }



}

